package com.ats.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ats.model.User;
import com.ats.service.FindMsgService_cl;
import com.ats.serviceimpl.FindMsgServiceImpl_cl;

import net.sf.json.JSONArray;

public class FindMsgController_cl extends HttpServlet{
		FindMsgService_cl fm = new FindMsgServiceImpl_cl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		HttpSession session = req.getSession(); 
		resp.setCharacterEncoding("utf8");
		PrintWriter pw = resp.getWriter();
		int uid = Integer.parseInt(req.getParameter("uid"));
		if (uid==1) {
			int iid =((User)session.getAttribute("user")).getIid();
			JSONArray arr = fm.FindMsgByIid(iid);
			pw.write(arr.toString());
			
		}else if(uid==2){
			int sid =((User)session.getAttribute("user")).getSid();
			JSONArray arr = fm.FindMsgByIid(sid);
			pw.write(arr.toString());
		}else if(uid==3){
			int tid =((User)session.getAttribute("user")).getTid();
			JSONArray arr = fm.FindMsgByIid(tid);
			pw.write(arr.toString());
		}
		
	}
}
